home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / C ƒ / TRANS-LSC / MSkelEdit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-04  |  2.9 KB  |  187 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel multiple-window demonstration: TextEdit module
  3.  
  4.     This module handles a simple TextEdit window, in which text may be
  5.     typed and standard Cut/Copy/Paste/Clear operations may be performed.
  6.     Undo is not supported, nor is text scrolling.
  7.  
  8.     14 June 1986        Paul DuBois
  9. */
  10.  
  11. # include    "MultiSkel.h"
  12. # include    <TextEdit.h>
  13.  
  14.  
  15. /* edit menu item numbers */
  16.  
  17. typedef enum {
  18.     undo = 1,
  19.     /* --- */
  20.     cut = 3,
  21.     copy,
  22.     paste,
  23.     clear
  24. } editItems;
  25.  
  26.  
  27.  
  28. /*
  29.     Text Window - simple text editing window
  30. */
  31.  
  32. WindowPtr            editWind;
  33. static TEHandle        teEdit;        /* handle to text window TextEdit record */
  34.  
  35.  
  36. static Halt ()
  37. {
  38.     TEDispose (teEdit);
  39.     CloseWindow (editWind);
  40. }
  41.  
  42.  
  43. static Idle ()
  44. {
  45.     TEIdle (teEdit);    /* blink that cursor! */
  46. }
  47.  
  48.  
  49. static Key (ch, mods)
  50. char    ch;
  51. int        mods;
  52. {
  53.     TEKey (ch, teEdit);
  54. }
  55.  
  56.  
  57. static Mouse (thePt, t, mods)
  58. Point    thePt;
  59. long    t;
  60. int        mods;
  61. {
  62.     TEClick (thePt, (mods & shiftKey) != 0, teEdit);
  63. }
  64.  
  65.  
  66. /*
  67.     Update text window.  The update event might be in response to a
  68.     window resizing.  If so, resize the rects and recalc the linestarts
  69.     of the text.  To resize the rects, only the right edge of the
  70.     destRect need be changed (the bottom is not used, and the left and
  71.     top should not be changed). The viewRect should be sized to the
  72.     screen.
  73. */
  74.  
  75. static Update (resized)
  76. Boolean    resized;
  77. {
  78. Rect    r;
  79.  
  80.     r = editWind->portRect;
  81.     EraseRect (&r);
  82.     r.left += 4;
  83.     r.bottom -= 2;
  84.     r.top += 2;
  85.     r.right -= 19;
  86.     if (resized)
  87.     {
  88.         (**teEdit).destRect.right = r.right;
  89.         (**teEdit).viewRect = r;
  90.         TECalText (teEdit);
  91.     }
  92.     DrawGrowBox (editWind);
  93.     TEUpdate (&r, teEdit);
  94. }
  95.  
  96.  
  97. static Activate (active)
  98. Boolean    active;
  99. {
  100.     DrawGrowBox (editWind);
  101.     if (active)
  102.     {
  103.         TEActivate (teEdit);
  104.         DisableItem (editMenu, undo);
  105.     }
  106.     else
  107.     {
  108.         TEDeactivate (teEdit);
  109.         EnableItem (editMenu, undo);
  110.     }
  111. }
  112.  
  113.  
  114. /*
  115.     Handle Edit menu items for text window
  116. */
  117.  
  118. EditWindEditMenu (item)
  119. int        item;
  120. {
  121.     switch (item)
  122.     {
  123. /*
  124.     cut selection, put in TE Scrap, clear clipboard and put
  125.     TE scrap in it
  126. */
  127.         case cut:
  128.         {
  129.             TECut (teEdit);
  130.             (void) ZeroScrap ();
  131.             (void) TEToScrap ();
  132.             break;
  133.         }
  134. /*
  135.     copy selection to TE Scrap, clear clipboard and put
  136.     TE scrap in it
  137. */
  138.         case copy:
  139.         {
  140.             TECopy (teEdit);
  141.             (void) ZeroScrap ();
  142.             (void) TEToScrap ();
  143.             break;
  144.         }
  145. /*
  146.     get clipboard into TE scrap, put TE scrap into edit record
  147. */
  148.         case paste:
  149.         {
  150.             (void) TEFromScrap ();
  151.             TEPaste (teEdit);
  152.             break;
  153.         }
  154. /*
  155.     delete selection without putting into TE scrap or clipboard
  156. */
  157.         case clear:
  158.         {
  159.             (void) TEDelete (teEdit);
  160.             break;
  161.         }
  162.     }
  163. }
  164.  
  165.  
  166. EditWindInit ()
  167. {
  168. Rect    r;
  169. StringPtr    str;
  170.  
  171.     editWind = GetNewWindow (editWindRes, nil, -1L);
  172.     SkelWindow (editWind, Mouse, Key, Update,
  173.                 Activate, nil, Halt, Idle, true);
  174.  
  175.     TextFont (0);
  176.     TextSize (0);
  177.  
  178.     r = editWind->portRect;
  179.     r.left += 4;
  180.     r.bottom -= 2;
  181.     r.top += 2;
  182.     r.right -= 19;
  183.     teEdit = TENew (&r, &r);
  184.     str = (StringPtr) "\pThis is the text editing window.\r";
  185.     TEInsert (&str[1], (long) str[0], teEdit);
  186. }
  187.